﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class PRODUCT_BUILD
    {
        private double m_Amount;
        private string m_BuildID;
        private double m_Price;
        private string m_ProductID;
        private double m_Quantity;

        public PRODUCT_BUILD()
        {
            this.m_ProductID = "";
            this.m_BuildID = "";
            this.m_Quantity = 0.0;
            this.m_Price = 0.0;
            this.m_Amount = 0.0;
        }

        public PRODUCT_BUILD(string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            this.m_ProductID = ProductID;
            this.m_BuildID = BuildID;
            this.m_Quantity = Quantity;
            this.m_Price = Price;
            this.m_Amount = Amount;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "PRODUCT_BUILDName", "PRODUCT_BUILDID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["PRODUCT_BUILDID"] = "All";
            row["PRODUCT_BUILDName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "PRODUCT_BUILDName", "PRODUCT_BUILDID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { this.m_ProductID, this.m_BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Delete", myParams, myValues);
        }

        public string Delete(string BuildID)
        {
            string[] myParams = new string[] { "@BuildID" };
            object[] myValues = new object[] { BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Delete_Product", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string BuildID)
        {
            string[] myParams = new string[] { "@BuildID" };
            object[] myValues = new object[] { BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_BUILD_Delete_Product", myParams, myValues);
        }

        public string Delete(string ProductID, string BuildID)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string ProductID, string BuildID)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_BUILD_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string ProductID, string BuildID)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_BUILD_Delete", myParams, myValues);
        }

        public bool Exist(string ProductID, string BuildID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_BUILD_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string ProductID, string BuildID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("PRODUCT_BUILD_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductID = Convert.ToString(reader["ProductID"]);
                    this.m_BuildID = Convert.ToString(reader["BuildID"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_Price = Convert.ToSingle(reader["Price"]);
                    this.m_Amount = Convert.ToSingle(reader["Amount"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string ProductID, string BuildID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "PRODUCT_BUILD_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductID = Convert.ToString(reader["ProductID"]);
                    this.m_BuildID = Convert.ToString(reader["BuildID"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_Price = Convert.ToSingle(reader["Price"]);
                    this.m_Amount = Convert.ToSingle(reader["Amount"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string ProductID, string BuildID)
        {
            string str = "";
            string[] myParams = new string[] { "@ProductID", "@BuildID" };
            object[] myValues = new object[] { ProductID, BuildID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "PRODUCT_BUILD_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_ProductID = Convert.ToString(reader["ProductID"]);
                    this.m_BuildID = Convert.ToString(reader["BuildID"]);
                    this.m_Quantity = Convert.ToSingle(reader["Quantity"]);
                    this.m_Price = Convert.ToSingle(reader["Price"]);
                    this.m_Amount = Convert.ToSingle(reader["Amount"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_BUILD_GetList");
        }

        public DataTable GetList(string Product_ID)
        {
            string[] myParams = new string[] { "@Product_ID" };
            object[] myValues = new object[] { Product_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_BUILD_GetList_Product", myParams, myValues);
        }

        public DataTable GetListBuild(string BuildID)
        {
            string[] myParams = new string[] { "@BuildID" };
            object[] myValues = new object[] { BuildID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("PRODUCT_BUILD_Get_By_ID", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { this.m_ProductID, this.m_BuildID, this.m_Quantity, this.m_Price, this.m_Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { this.m_ProductID, this.m_BuildID, this.m_Quantity, this.m_Price, this.m_Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_BUILD_Insert", myParams, myValues);
        }

        public string Insert(string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_BUILD_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_BUILD_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("PRODUCT_BUILD", "PRODUCT_BUILDID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { this.m_ProductID, this.m_BuildID, this.m_Quantity, this.m_Price, this.m_Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Update", myParams, myValues);
        }

        public string Update(string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("PRODUCT_BUILD_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "PRODUCT_BUILD_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string ProductID, string BuildID, double Quantity, double Price, double Amount)
        {
            string[] myParams = new string[] { "@ProductID", "@BuildID", "@Quantity", "@Price", "@Amount" };
            object[] myValues = new object[] { ProductID, BuildID, Quantity, Price, Amount };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "PRODUCT_BUILD_Update", myParams, myValues);
        }

        public double Amount
        {
            get
            {
                return this.m_Amount;
            }
            set
            {
                this.m_Amount = value;
            }
        }

        public string BuildID
        {
            get
            {
                return this.m_BuildID;
            }
            set
            {
                this.m_BuildID = value;
            }
        }

        public double Price
        {
            get
            {
                return this.m_Price;
            }
            set
            {
                this.m_Price = value;
            }
        }

        public string ProductID
        {
            get
            {
                return this.m_ProductID;
            }
            set
            {
                this.m_ProductID = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class PRODUCT_BUILD";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public double Quantity
        {
            get
            {
                return this.m_Quantity;
            }
            set
            {
                this.m_Quantity = value;
            }
        }
    }
}

